package zeebe.gateway.Parallel;

import io.zeebe.client.ZeebeClient;

import java.util.Arrays;
import java.util.List;

public class ParallelGatewayDeploy {
    public static void main(String[] args) {
        System.out.println("创建Zeebe的连接");
        ZeebeClient client = ZeebeClient.newClientBuilder()
                .brokerContactPoint("localhost:26500")
                .usePlaintext()
                .build();

        System.out.println("部署工作流");
        String bpmnPath = "bpmn/parallelGateway.bpmn";
        client.newDeployCommand()
                .addResourceFromClasspath(bpmnPath)
                .send()
                .join();

        System.out.println("部署AJobWorker");
        String aType = "a";
        AJobWorkerHandler aHandler = new AJobWorkerHandler(client);
        client.newWorker()
                .jobType(aType)
                .handler(aHandler)
                .open();

        System.out.println("部署BJobWorker");
        String bType = "b";
        BJobWorkerHandler bHandler = new BJobWorkerHandler(client);
        client.newWorker()
                .jobType(bType)
                .handler(bHandler)
                .open();

        System.out.println("部署CJobWorker");
        String cType = "c";
        List<String> list= Arrays.asList("A","B");
        CJobWorkerHandler cHandler = new CJobWorkerHandler(client);
        client.newWorker()
                .jobType(cType)
                .handler(cHandler)
                .fetchVariables(list)
                .open();
    }
}
